package cn.com.surker.material.dao;

import cn.com.surker.dto.main.MaterialWeightQueryDTO;
import cn.com.surker.material.entity.MainMaterialWeight;
import cn.com.surker.material.vo.MainMaterialWeightVo;
import cn.com.surker.vo.main.MainMaterialVO;
import cn.com.surker.vo.main.MainMaterialWeightVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * <p>
 * 材料过磅表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2024-06-29
 */
public interface MainMaterialWeightDao extends BaseMapper<MainMaterialWeight> {


    /**
     * 分页查询过磅明细
     * @param page
     * @param queryWrapper
     * @param <E>
     * @return
     */
    <E extends IPage<MainMaterialWeight>> E findWeightPage(E page, @org.apache.ibatis.annotations.Param(Constants.WRAPPER) Wrapper<MainMaterialWeight> queryWrapper);
    /**
     * 分页查询过磅明细
     * @param page
     * @param queryWrapper
     * @param <E>
     * @return
     */
    <E extends IPage<MainMaterialWeight>> E findCloudWeightPage(E page, @org.apache.ibatis.annotations.Param(Constants.WRAPPER) Wrapper<MainMaterialWeight> queryWrapper, String dbCode);

    List<MainMaterialWeightVO> findCloudWeightPage(@org.apache.ibatis.annotations.Param(Constants.WRAPPER) Wrapper<MainMaterialWeight> queryWrapper, String dbCode);

    /**
     * 统计云端累计数据
     * @param queryWrapper
     * @param dbCode
     * @return
     */
    MainMaterialWeightVO findCloudTotalWeightPage(@org.apache.ibatis.annotations.Param(Constants.WRAPPER) Wrapper<MainMaterialWeight> queryWrapper, String dbCode);

    IPage<MainMaterialWeightVO> pageData(@Param("page") Page page, @Param("dto") MaterialWeightQueryDTO dto);

    /**
     * 根据id查询过磅信息
     * @param id
     * @return
     */
    MainMaterialWeightVO selectByIdV1(Long id, String dbCode);

    /**
     * 执行update sql
     * @param updateSql
     * @return
     */
    Integer updateCloudSql(String updateSql);

    /**
     * 统计查询各供应商进料数据
     * @param dbCode 云端数据库号
     * @param orgId
     * @param supplierId
     * @param materialId
     * @param type 0地材 1非地材
     * @param searchVal
     * @param startTime
     * @param endTime
     * @return
     */
    List<MainMaterialWeightVO> findCloudTotalSupplier(String dbCode, Long orgId, Long supplierId, Long materialId,
                                                      String type, String searchVal, String startTime, String endTime);

    /**
     * 查詢供应商过磅时间及过磅时间
     * @param orgId
     * @param supplierId 供应商id
     * @param materialId 材料id
     * @param carType 车辆类型 WeightCarTypeEnum 2材料车
     * @param weightType 过磅类型 OrderWeightTypeEnum 1原材
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    List<MainMaterialWeightVo> findSupplierWeight(String dbCode, Long orgId, Long supplierId, Long materialId, Integer carType,
                                                  Integer weightType, String startTime, String endTime);

    /**
     * 查询某个时间段的过磅净重
     * @param storageId 仓位ID
     * @param materialId 材料ID
     * @param carType 车辆类型
     * @param weightType 过磅类型
     * @param startTime
     * @param endTime
     * @return
     */
    Double findSumNetWeight(Long storageId, Long materialId, Integer carType, Integer weightType, String startTime, String endTime);

    Double findCloudSumNetWeight(String dbCode,Long storageId, Long materialId, Integer carType, Integer weightType,
                                 String startTime, String endTime, Long orgId, Integer breedType);

    /**
     * 新增云端数据
     * @param weight
     * @return
     */
    Integer saveCloud(@Param("weight") MainMaterialWeight weight, String dbCode);

    /**
     * 材料大类过磅重量
     * @param dbCode
     * @param breedType
     * @return
     */
    List<MainMaterialWeightVo> findBreedWeight(String dbCode, Integer breedType, String startTime, String endTime);

    /**
     * 根据仓位统计进料数据
     * @return
     */
    List<MainMaterialWeightVo> findStorageWeight(String dbCode, String searchVal, Long supplierId, Long materialId,
              Long storageId, Integer breedType, Integer storageType, String startTime, String endTime);
}
